package org.mineground.player.groupchat;

import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;

/**
 * @file GroupChat.java (20.02.2012)
 * @author Daniel Koenen
 *
 */
public class GroupChat {
    private int groupId;
    private String groupName;
    private long groupPassword;
    
    private List<Player> onlineGroupPlayers = new ArrayList<Player>();
    
    public GroupChat(int groupId, String groupName, long groupPassword) {
        this.groupId = groupId;
        this.groupName = groupName;
        this.groupPassword = groupPassword;
    }
    
    public ArrayList<Player> getMemberPage(int pageNumber) {
        int iterator = 0;
        ArrayList<Player> viewableList = new ArrayList<Player>();
        for (Player player : onlineGroupPlayers) {
	    if (iterator >= (pageNumber - 1) * 5 && iterator < (pageNumber * 5)) {
		viewableList.add(player);
	    }

	    iterator++;
	}
        
        return viewableList;
    }
    
    public int getTotalPages() {
        int index = onlineGroupPlayers.size(); 
        int rest = index % 5;
        int totalPages = (index - rest) / 5;
        return (rest == 0) ? (totalPages) : (totalPages + 1);
    }
    
    public void addPlayer(Player player) {
        onlineGroupPlayers.add(player);
    }
    
    public void removePlayer(Player player) {
        onlineGroupPlayers.remove(player);
    }
    
    public List<Player> getGroupPlayers() {
        return onlineGroupPlayers;
    }

    public int getGroupId() {
        return groupId;
    }

    public String getGroupName() {
        return groupName;
    }

    public long getGroupPassword() {
        return groupPassword;
    }

    public void setGroupPassword(long groupPassword) {
        this.groupPassword = groupPassword;
    }
}
